/*
 * @Author: hechengfei h349187021@163.com
 * @Date: 2022-08-11 14:16:34
 * @LastEditors: hechengfei h349187021@163.com
 * @LastEditTime: 2022-08-23 16:01:53
 * @FilePath: \xiangmu\src\components\contractmanagement\ContractTable.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Space, Table, Radio } from 'antd';
import React, { useState } from 'react';
import '../../assets/css/contract/ContractTable.css'
import { inject, observer } from 'mobx-react'
import { Modal, Button } from 'antd';
import RenewalTable from './RenewalTable';
import Newrenewal from './Newrenewal';
import Changcontractinfo from './Changcontractinfo';
const ContractTable = (props) => {
    const [isModalVisible2, setIsModalVisible2] = useState(false);
    const [isModalVisible1, setIsModalVisible1] = useState(false);
    const [isModalVisible3, setIsModalVisible3] = useState(false);
    const [isModalVisible4, setIsModalVisible4] = useState(false);
    const [isModalVisible5, setIsModalVisible5] = useState(false);
    const [value, setvalue] = useState(null);
    const [daokuan, setdaokuan] = useState({})
    const [to_the_paragraph, setto_the_paragraph] = useState('')
    const [remarks, setremarks] = useState('')
    let daokuanshuju = {};
    const data = props.contractStore.DisplayContractInfo
    const showModal2 = (e) => {
        setIsModalVisible2(true);
        props.contractStore.getconractrenewaltable({ currentPage: props.contractStore.currentPage, pageSize: props.contractStore.pageSize })
    };
    const handleOk2 = () => {
        setIsModalVisible2(false);
    };
    const handleCancel2 = () => {
        setIsModalVisible2(false);
    };
    const showModal3 = (record) => {
        setIsModalVisible3(true);
        props.contractStore.feedlist = {
            contract_no: record.contract_no,
            end_date: record.end_date,
            entry_time: record.entry_time,
            received: record.received,
            remarks: record.remarks,
            renewal_record: record.renewal_record,
            total_amount: record.total_amount,
            user_name: record.user_name,
        }

    };
    const handleOk3 = () => {
        setIsModalVisible3(false);
        props.contractStore.getsearchfeedlist(props.contractStore.feedlist);
    };
    const handleCancel3 = () => {
        setIsModalVisible3(false);
    };
    const showModal4 = (record) => {
        setIsModalVisible4(true);
        console.log(record.contract_no);
        setdaokuan({
            contract_no: record.contract_no,
            total_amount: record.total_amount,
            received: record.received,
            arrears: record.arrears,
        })
    };
    const handleOk4 = () => {
        setIsModalVisible4(false)
        daokuanshuju = { ...daokuan, remark: remarks, to_the_paragraph: to_the_paragraph }
        console.log(daokuanshuju);
        props.contractStore.getchangetomoneycome(daokuanshuju)
        setto_the_paragraph('')
        setremarks('')
    };
    const handleCancel4 = () => {
        setIsModalVisible4(false);
    };
    const totheparagraph = (e) => {
        setto_the_paragraph(e.target.value)
    }
    const totheparagraphremark = (e) => {
        setremarks(e.target.value)
    }
    const showModal5 = (record) => {
        setIsModalVisible5(true);
        props.contractStore.changecontractinfo = {
            customer_name: record.customer_name,
            contract_no: record.contract_no,
            contract_classification: record.contract_classification,
            order_number: record.order_number,
            start_date: record.start_date,
            end_date: record.end_date,
            total_amount: record.total_amount,
            received: record.received,
            include_tax: record.include_tax,
            provide_invoice: record.provide_invoice,
            remarks: record.remarks,
            user_name: record.user_name,
            annex: record.annex,
            audit_personnel: record.audit_personnel,
            audit_time: record.audit_time,
            contract_status: record.contract_status,
            contract_id: record.contract_id,
            arrears: record.arrears,

        }
    };
    const handleOk5 = () => {
        setIsModalVisible5(false)
        props.contractStore.getchangecontractinfobyname(props.contractStore.changecontractinfo);
    };
    const handleCancel5 = () => {
        setIsModalVisible5(false);
    };

    const showModal1 = ({ contract_status, contract_no }) => {
        setIsModalVisible1(true);
        console.log('contract_status', contract_status);
        props.contractStore.contractStutebyno = contract_no
        setvalue(contract_status)
        console.log('value', value);
    };
    const handleOk1 = () => {
        setIsModalVisible1(false);
        props.contractStore.getchangestatue({ contract_status: value, contract_no: props.contractStore.contractStutebyno })
        props.contractStore.getcontractData({ currentPage: props.contractStore.currentPage, pageSize: props.contractStore.pageSize })

    };
    const handleCancel1 = () => {
        setIsModalVisible1(false);
    };
    const onChange = (e) => {
        setvalue(e.target.value);
    };
    const deletecontract = (contract_no) => {
        props.contractStore.getdeletecontractinfobyno(contract_no)
        props.contractStore.getcontractData({ currentPage: props.contractStore.currentPage, pageSize: props.contractStore.pageSize })
    }
    const columns = [
        {
            title: '客户名称',
            dataIndex: 'customer_name',
            key: 'customer_name',
            render: (text) => <a>{text}</a>,
        },
        {
            title: '合同编号',
            dataIndex: 'contract_no',
            key: 'contract_no',
            render: (text) => <a type="primary" onClick={() => showModal2({ text })}>{text}</a>,
        },
        {
            title: '起始日期',
            dataIndex: 'start_date',
            key: 'start_date',
        },
        {
            title: '结束日期',
            dataIndex: 'end_date',
            key: 'end_date',
        },
        {
            title: '合同分类',
            dataIndex: 'contract_classification',
            key: 'contract_classification',
            render: (text) => {
                if (text === 1) {
                    text = '买卖'
                } else if (text === 2) {
                    text = '工程'
                } else if (text === 3) {
                    text = '技术'
                } else if (text === 4) {
                    text = '委托'
                } else if (text === 5) {
                    text = '租赁'
                } else {
                    text = '其他'
                }
                return <text>{text}</text>
                // <Option value="1">买卖</Option>
                //         <Option value="2">租赁</Option>
                //         <Option value="3">工程</Option>
                //         <Option value="4">技术</Option>
                //         <Option value="5">委托</Option>
                //         <Option value="6">其他</Option>
            },
        },
        {
            title: '总金额',
            dataIndex: 'total_amount',
            key: 'total_amount',
        },
        {
            title: '已收款',
            dataIndex: 'received',
            key: 'received',
        },
        {
            title: '欠款',
            dataIndex: 'arrears',
            key: 'arrears',
        },
        {
            title: '提供发票',
            dataIndex: 'provide_invoice',
            key: 'provide_invoice',
        },
        {
            title: '合同状态',
            dataIndex: 'contract_status',
            key: 'contract_status',
            render: (text, record) => {
                if (text === 1) {
                    text = '合同有效'
                    props.contractStore.contractStute = 1
                } else if (text === 2) {
                    text = "合同无效"
                    props.contractStore.contractStute = 2
                } else {
                    text = "转待审"
                    props.contractStore.contractStute = 3
                }
                return <Button type='primary' onClick={() => { showModal1({ contract_status: record.contract_status, contract_no: record.contract_no }) }
                } > {text}</Button >
            }
        },
        {
            title: '审核时间',
            dataIndex: 'audit_time',
            key: 'audit_time',
        },
        {
            title: '备注',
            dataIndex: 'remarks',
            key: 'remarks',
        },
        {
            title: '业务员',
            dataIndex: 'user_name',
            key: 'user_name',
        },
        {
            title: '录入时间',
            dataIndex: 'entry_time',
            key: 'entry_time',
        },
        {
            title: '附件',
            dataIndex: 'annex',
            key: 'annex',
        },
        {
            title: '管理',
            key: 'contract_id',
            render: (record) => {
                return < Space size="middle" >
                    <button className='ContractTablexvfei' onClick={() => { showModal3(record) }}>续费</button>
                    <button className='ContractTablexvfei' onClick={() => { showModal4(record) }}>到款</button>
                    <button className='ContractTablexiugai' onClick={() => { showModal5(record) }}>修改</button>
                    <button className='ContractTabledelet' onClick={() => { deletecontract(record.contract_no) }}>删除</button>
                </ Space >
            }


            ,
        },
    ];
    return (
        <div>
            <Table columns={columns} dataSource={data} pagination={false} />
            <>
                <Modal title="查看续费" width={1000} visible={isModalVisible2} onOk={handleOk2} onCancel={handleCancel2}>
                    <RenewalTable />
                </Modal>
            </>
            <>
                <Modal title="合同状态" visible={isModalVisible1} onOk={handleOk1} onCancel={handleCancel1}>
                    <Radio.Group onChange={onChange} value={value}>
                        <span>状态：</span>
                        <Radio value={1}>合同有效</Radio>
                        <Radio value={2}>合同无效</Radio>
                        <Radio value={3}>待审转</Radio>
                    </Radio.Group>
                </Modal>
            </>
            <>
                <Modal title="新增合同续费" width={1000} visible={isModalVisible3} onOk={handleOk3} onCancel={handleCancel3}>
                    <Newrenewal />
                </Modal>
            </>
            <>
                <Modal title="合同到款" visible={isModalVisible4} onOk={handleOk4} onCancel={handleCancel4}>
                    <div>
                        <div>
                            <span>到款</span><input value={to_the_paragraph} onChange={(e) => { totheparagraph(e) }} type="text" />
                        </div>
                        <div>
                            <span>备注</span><input value={remarks} onChange={(e) => { totheparagraphremark(e) }} type="text" />
                        </div>
                    </div>
                </Modal>
            </>
            <>
                <Modal title="修改合同" visible={isModalVisible5} onOk={handleOk5} onCancel={handleCancel5}>
                    <Changcontractinfo />
                </Modal>
            </>
        </div >


    )
}

export default inject('contractStore')(observer(ContractTable));